﻿using Magicodes.ExporterAndImporter.Excel.AspNetCore;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using NP.BPMReportPlatform.AnalysisInstance.Dtos;
using System.IO;
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;

namespace NP.BPMReportPlatform.IU
{
    /// <summary>
    /// IU接口
    /// </summary>
    [Authorize]
    [ApiController]
    [Route("api/iu")]
    public class IUController : BPMReportPlatformController
    {
        private readonly IIUAppService _iuService;

        public IUController(IIUAppService iuService)
        {
            _iuService = iuService;
        }

        /// <summary>
        /// 委外检测流程 查询数据
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("OutsourceCheck/GetAllAsync")]
        public async Task<PagedResultDto<GetOutsourceCheckOutput>> GetAllAsync([FromBody] GetOutsourceCheckInput input)
        {
            return await _iuService.GetAllAsync(input);
        }

        /// <summary>
        ///  委外检测流程  导出数据
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("OutsourceCheck/ExportAsync")]
        public async Task<XlsxFileResult<GetOutsourceCheckOutput>> ExportAsync([FromBody] GetOutsourceCheckInput input)
        {
            var rst = await _iuService.ExportAsync(input);
            return new XlsxFileResult<GetOutsourceCheckOutput>(rst, "导出Excel");
        }

        /// <summary>
        /// IU槽液检测录入 查询数据
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("CYJC/GetAllAsync")]
        public async Task<PagedResultDto<GetCYJCOutput>> GetAllAsync([FromBody] GetCYJCInput input)
        {
            return await _iuService.GetAllAsync(input);
        }

        /// <summary>
        ///  IU槽液检测录入  导出数据
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("CYJC/ExportAsync")]
        public async Task<XlsxFileResult<GetCYJCOutput>> ExportAsync([FromBody] GetCYJCInput input)
        {
            var rst = await _iuService.ExportAsync(input);
            return new XlsxFileResult<GetCYJCOutput>(rst, "导出Excel");
        }


        /// <summary>
        ///  IU槽液检测分析报表  导出数据
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("CYJCFX/ExportAsync")]
        public async Task<FileContentResult> ExportAnalysisInstances([FromBody] GetCYJCFXInput input)
        {
            var data = await _iuService.ExportAsync(input);
            var ms = new MemoryStream();
            data.Write(ms);
            data.Close();
            return File(ms.ToArray(), "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
        }
    }
}